using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Plugin.Sns.Scene;
using MicroMsg.Storage;
using System;
using System.Collections.Generic;
using System.Windows;
namespace MicroMsg.Manager
{
	public class SnsMediaMgr
	{
		private const string TAG = "SnsMediaMgr";
		private static List<snsMediaDownloadInfo> exceptionList = new List<snsMediaDownloadInfo>();
		public static bool getImg(snsMediaDownloadInfo mediaInfo, bool isSyncLoad = true)
		{
			using (List<snsMediaDownloadInfo>.Enumerator enumerator = SnsMediaMgr.exceptionList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					snsMediaDownloadInfo current = enumerator.get_Current();
					if (current.snsObjID == mediaInfo.snsObjID && current.string_0 == mediaInfo.string_0)
					{
						Log.smethod_1("SnsMediaMgr", string.Concat(new object[]
						{
							"imgInfo exists in listException , snsObjID = ",
							mediaInfo.snsObjID,
							" url = ",
							mediaInfo.string_0
						}));
						bool result = false;
						return result;
					}
				}
			}
			if (SnsMediaStorage.exists(mediaInfo.string_0))
			{
				if (isSyncLoad)
				{
					mediaInfo.object_0 = ImageCacheMgr.loadFromBuf(SnsMediaStorage.load(mediaInfo.string_0));
				}
				else
				{
					Deployment.get_Current().get_Dispatcher().BeginInvoke(delegate
					{
						mediaInfo.object_0 = ImageCacheMgr.loadFromBuf(SnsMediaStorage.load(mediaInfo.string_0));
						EventCenter.postEvent(EventConst.ON_MGR_SNS_GET_MEDIA_FINISH, mediaInfo, null);
					});
				}
				return mediaInfo.object_0 != null;
			}
			return DownloadMediaService.downloadSnsInfo(mediaInfo);
		}
		public static bool save(snsMediaDownloadInfo info, byte[] byte_0)
		{
			info.object_0 = ImageCacheMgr.loadFromBuf(byte_0);
			if (info.object_0 == null)
			{
				Log.smethod_1("SnsMediaMgr", "loadFromBuf fail");
				SnsMediaMgr.exceptionList.Add(info);
				return false;
			}
			if (!SnsMediaStorage.save(info.string_0, byte_0))
			{
				Log.smethod_1("SnsMediaMgr", "save file fail");
				SnsMediaMgr.exceptionList.Add(info);
				return false;
			}
			return true;
		}
	}
}
